
//使用两个线程来累加 count 的值
//每个线程循环 1w 次，累加变量 count 的值，count 默认值为 0，注意线程安全问题。
public class Thread1 {
    private static int count;
    private static Object lock = new Object();
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(()->{
            for (int i = 0; i < 10000; i++) {
                synchronized(lock){
                count +=1;
                }
            }
        });
        Thread thread2 = new Thread(()->{
            for (int i = 0; i < 10000; i++) {
                synchronized(lock){
                count +=1;
                }
            }
        });
        thread.start();
        thread2.start();
        thread.join();
        thread2.join();
        System.out.println(count);
    }
}
